package com.irdstudio.efp.cus.service.impl;

import com.alibaba.fastjson.JSON;
import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.cus.service.dao.CusReferrerInfoDao;
import com.irdstudio.efp.cus.service.domain.CusReferrerInfo;
import com.irdstudio.efp.cus.service.facade.CusReferrerInfoService;
import com.irdstudio.efp.cus.service.vo.CusReferrerInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * ServiceImpl: 推荐人信息表
 * <p>
 * 
 * @author dengqiwen
 * @date 2020-08-07
 */
@Service("cusReferrerInfoService")
public class CusReferrerInfoServiceImpl  implements CusReferrerInfoService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(CusReferrerInfoServiceImpl.class);

	@Autowired
	private CusReferrerInfoDao cusReferrerInfoDao;


	@Override
	public int insertCusReferrerInfo(CusReferrerInfoVO cusVo){
		logger.info("新增推荐人信息表数据开始");
		int num = 0;
		try {
			CusReferrerInfo cus = new CusReferrerInfo();
			beanCopy(cusVo, cus);
			num=cusReferrerInfoDao.insertCusReferrerInfo(cus);
		} catch (Exception e) {
			String errorMsg="新增【推荐人信息表】异常："+e.getMessage();
			logger.error(errorMsg);
			num=-1;
		}
        return num;
	}

	@Override
	public List<CusReferrerInfoVO> queryCusReferByCond(CusReferrerInfoVO vo){
		logger.info("当前查询推荐人信息的参数信息为:");
		CusReferrerInfo cus = beanCopy(vo, new CusReferrerInfo());
		List<CusReferrerInfo> cusRefs = new ArrayList<CusReferrerInfo>();
		try {
			cusRefs = cusReferrerInfoDao.queryCusReferByCond(cus);
			logger.info("当前查询推荐人信息的结果集数量为:" + cusRefs.size());
			 return (List<CusReferrerInfoVO>) beansCopy(cusRefs, CusReferrerInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
        return null;

	}

	@Override
	public int updateByPk(CusReferrerInfoVO vo){
		logger.debug("当前修改推荐人信息数据为:"+ vo.toString());
		CusReferrerInfo cus=null;
		int num = 0;
		try {
			cus=new CusReferrerInfo();
			beanCopy(vo,cus);
			int i = cusReferrerInfoDao.updateByPk(cus);
		} catch (Exception e) {
			logger.error("修改推荐人信息数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ vo +"修改的推荐人信息数据条数为"+ num);
		return num;
	}

	@Override
	public CusReferrerInfoVO queryChargeoffBrIdByPk(CusReferrerInfoVO cusVo){
		logger.info("当前查询推荐人信息表出账机构参数信息为:" + JSON.toJSONString(cusVo));
		try {
			CusReferrerInfo cus=new CusReferrerInfo();
			beanCopy(cusVo,cus);
			CusReferrerInfo queryCus=cusReferrerInfoDao.queryChargeoffBrIdByPk(cus);
			if (Objects.nonNull(queryCus)){
				logger.info("当前查询结果为:" + JSON.toJSONString(queryCus));
				return beanCopy(queryCus,new CusReferrerInfoVO());
			}else{
				logger.info("当前查询推荐人信息表出账机构结果为空!");
			}

		}catch (Exception e) {
			logger.error("当前查询推荐人信息表出账机构发生异常!", e);
		}
		return null;
	}

	@Override
	public List<CusReferrerInfoVO> queryTypeAndCode(CusReferrerInfoVO cusVo) {
		logger.info("当前查询推荐人信息表为:" + JSON.toJSONString(cusVo));
		try {
			CusReferrerInfo cus=new CusReferrerInfo();
			beanCopy(cusVo,cus);
			List<CusReferrerInfo> queryCus=cusReferrerInfoDao.queryTypeAndCode(cus);
			if (Objects.nonNull(queryCus)){
				logger.info("当前查询结果为:" + JSON.toJSONString(queryCus));
				return (List<CusReferrerInfoVO>) beansCopy(queryCus, CusReferrerInfoVO.class);
			}else{
				logger.info("当前查询推荐人信息表结果为空!");
			}
		}catch (Exception e) {
			logger.error("当前查询推荐人信息表发生异常!", e);
		}
		return null;
	}


}
